package local.blueheart.data.springdatademo.domain.archive;

import local.blueheart.data.springdatademo.domain.config.ApplicationDO;
import local.blueheart.data.springdatademo.domain.config.ModuleDO;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;
import java.util.Date;

@Entity
@IdClass(DocCompositedId.class)
@Data
@ToString(exclude = {"moduleDO", "applicationDO"})
public class ArchiveIndexData {

    private String docUniversalId;

    private String dbPath;

    private String docId;

    private String mainDocumentServer;

    private String subject;

    private String company;

    private String department;

    private String proccessName;

    private String proccessNameShow;

    private String serialWord;

    private String status;

    private String msg;

    private ModuleDO moduleDO;

    private ApplicationDO applicationDO;

    @Version
    private Integer version;

    private Date dateCreated;

    private Date lastUpdated;

    @PreUpdate
    @PrePersist
    public void updateTimeStamps() {
        lastUpdated = new Date();
        if (dateCreated == null) {
            dateCreated = new Date();
        }
    }


    @Id
    @Column(length = 64, nullable = false)
    public String getDocUniversalId() {
        return docUniversalId;
    }

    public void setDocUniversalId(String docUniversalId) {
        this.docUniversalId = docUniversalId;
    }

    @Id
    @Column(length = 64, nullable = false)
    public String getDbPath() {
        return dbPath;
    }

    public void setDbPath(String dbPath) {
        this.dbPath = dbPath;
    }

    public String getDocId() {
        return docId;
    }

    public void setDocId(String docId) {
        this.docId = docId;
    }

    public String getMainDocumentServer() {
        return mainDocumentServer;
    }

    public void setMainDocumentServer(String mainDocumentServer) {
        this.mainDocumentServer = mainDocumentServer;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getProccessName() {
        return proccessName;
    }

    public void setProccessName(String proccessName) {
        this.proccessName = proccessName;
    }

    public String getProccessNameShow() {
        return proccessNameShow;
    }

    public void setProccessNameShow(String proccessNameShow) {
        this.proccessNameShow = proccessNameShow;
    }

    public String getSerialWord() {
        return serialWord;
    }

    public void setSerialWord(String serialWord) {
        this.serialWord = serialWord;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, optional = false, fetch = FetchType.EAGER)
    @JoinColumn(name = "module_id")
    public ModuleDO getModuleDO() {
        return moduleDO;
    }

    public void setModuleDO(ModuleDO moduleDO) {
        this.moduleDO = moduleDO;
    }

    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, optional = false, fetch = FetchType.EAGER)
    @JoinColumn(name = "application_id")
    public ApplicationDO getApplicationDO() {
        return applicationDO;
    }

    public void setApplicationDO(ApplicationDO applicationDO) {
        this.applicationDO = applicationDO;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getLastUpdated() {
        return lastUpdated;
    }

    public void setLastUpdated(Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }
}
